﻿using FluentNHibernate.AutoMap;
using Webshop20.Domain.Shared.Payment.Core;
using FluentNHibernate.AutoMap.Alterations;

namespace Webshop20.Infrastructure.Persistence.NH.AutoMappings.Overrides
{
    public class IPaymentOverride : IAutoMappingOverride<IPayment>
    {
        public void Override(AutoMap<IPayment> mapping)
        {
            mapping.Id(x => x.Id, "IPaymentId").GeneratedBy.Increment();
            mapping.JoinedSubClass<DirectDebit>("DirectDebitId", sub =>
            {
                sub.WithTableName("DirectDebits");
                sub.Map(x => x.AccountNumber);
                sub.Map(x => x.AccountOwner);
                sub.Map(x => x.BankCode);
                sub.Map(x => x.BankName);
            });

            mapping.JoinedSubClass<CreditCard>("CreditCardId", sub =>
            {
                sub.WithTableName("CreditCards");
                sub.Map(x => x.ExpirationMonth);
                sub.Map(x => x.ExpirationYear);
                sub.Map(x => x.Number);
                sub.Map(x => x.Owner);
            });

            mapping.JoinedSubClass<Prepayment>("PrepaymentId", sub => { sub.WithTableName("Prepayments"); });
        }
    }
}
